//
//  AddSandTableViewController.m
//  YIJU2.0HD
//
//  Created by URANUS on 16/5/18.
//  Copyright © 2016年 Mr.X. All rights reserved.
//

#import "AddSandTableViewController.h"
#import "UIButton+NavRightBtn.h"
#import "DropdownMenuView.h"
#import "DropdownMenuViewUtil.h"
#import "Masonry.h"
#import "Macro.h"
#import "UILabel+ColorAndText.h"

@interface AddSandTableViewController () <UITextFieldDelegate>
@property (nonatomic, strong) UIButton *sureBtn;
@property (nonatomic, strong) UILabel *titleOne;
@property (nonatomic, strong) UILabel *TitleTwo;
@property (nonatomic, strong) DropdownMenuView *downChioceSandDropMenu;
@property (nonatomic, strong) UITextField *nameText;
@property (nonatomic, strong) NSArray *dropMenuArray;
@end

@implementation AddSandTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"添加沙盘";
    self.view.backgroundColor = kSettingBackgroundColor;
    [self dropMenuArray];
    [self setUpContaints];
}

#pragma mark - privte method
- (void)setUpContaints {
    [self sureBtn];
    
    UIView *downPayRatioBackView = [UIView new];
    downPayRatioBackView.backgroundColor = [UIColor whiteColor];
    downPayRatioBackView.layer.masksToBounds = YES;
    downPayRatioBackView.layer.cornerRadius = 3;
    [self.view addSubview:downPayRatioBackView];
    
    //选择类型title
    [self.titleOne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(TweentyOffsetViewMargin + 64);
        make.left.equalTo(self.view.mas_left).offset(TenOffsetViewMargin +5);
        make.width.equalTo(self.view.mas_width).multipliedBy(1/7.0f);
        make.height.mas_equalTo(ScreenHeight*0.05);
    }];
    
    //下拉菜单
    [downPayRatioBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleOne.mas_top);
        make.left.equalTo(self.titleOne.mas_right);
        make.right.equalTo(self.view.mas_right).offset(-TweentyOffsetViewMargin);
        make.height.mas_equalTo(ScreenHeight*0.05);
    }];
    
    //沙盘名称title
    [self.TitleTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleOne.mas_bottom).offset(TenOffsetViewMargin);
        make.left.equalTo(self.view.mas_left).offset(TenOffsetViewMargin + FiveOffsetViewMargin);
        make.width.equalTo(self.view.mas_width).multipliedBy(1/7.0f);
        make.height.mas_equalTo(ScreenHeight*0.05);
    }];
    
    //沙盘名称
    [self.nameText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.TitleTwo.mas_top);
        make.left.equalTo(self.TitleTwo.mas_right);
        make.right.equalTo(self.view.mas_right).offset(-TweentyOffsetViewMargin);
        make.height.mas_equalTo(ScreenHeight*0.05);
    }];
    
    __weak typeof(self) weakSelf = self;
    _downChioceSandDropMenu = [DropdownMenuViewUtil loadDropdownMenuViewWithTitle:nil withDropdownMenuContentTitleArray:_dropMenuArray andBackView:downPayRatioBackView];
    _downChioceSandDropMenu.selectedAtIndex = ^(int index){
        DDLogInfo(@"%@",weakSelf.dropMenuArray[index]);
    };
}

#pragma mark - Event Response
- (void)handleBtnAction:(UIButton *)button {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - Getter method
- (UIButton *)sureBtn {
    if (_sureBtn == nil) {
        _sureBtn = [UIButton btnWithTitle:@"确定"];
        _sureBtn.tag = 500;
        [_sureBtn addTarget:self action:@selector(handleBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *editItem = [[UIBarButtonItem alloc] initWithCustomView:_sureBtn];
        self.navigationItem.rightBarButtonItem = editItem;
    }
    return _sureBtn;
}

- (UILabel *)titleOne {
    if (!_titleOne) {
        _titleOne = [UILabel lableWithBackgroundColor:[UIColor clearColor] textFont:17 textColor:[UIColor blackColor] title:@"选择类型:"];
        _titleOne.textAlignment = NSTextAlignmentLeft;
        [self.view addSubview:_titleOne];
    }
    return _titleOne;
}

- (UILabel *)TitleTwo {
    if (!_TitleTwo) {
        _TitleTwo = [UILabel lableWithBackgroundColor:[UIColor clearColor] textFont:17 textColor:[UIColor blackColor] title:@"名称:"];
        _TitleTwo.textAlignment = NSTextAlignmentLeft;
        [self.view addSubview:_TitleTwo];
    }
    return _TitleTwo;
}

- (UITextField *)nameText {
    if (!_nameText) {
        _nameText = [[UITextField alloc] init];
        _nameText.layer.cornerRadius = 3.0f;
        _nameText.backgroundColor = [UIColor whiteColor];
        _nameText.delegate = self;
        [self.view addSubview:_nameText];
    }
    return _nameText;
}

- (NSArray *)dropMenuArray {
    if (!_dropMenuArray) {
        _dropMenuArray = @[@"占",@"着",@"茅",@"坑",@"不",@"拉",@"屎"];
    }
    return _dropMenuArray;
}

@end
